package com.xoa.service.attend;
import com.xoa.dao.attendance.AttendLeaveParamMapper;
import com.xoa.model.attend.AttendHoliday;
import com.xoa.model.attendance.AttendLeaveParam;
import com.xoa.util.ToJson;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AttendLeaveParamService {

    @Resource
    private AttendLeaveParamMapper attendLeaveParamMapper;

    /**
     * 新增年假参数
     * @param attendLeaveParam
     * @return
     */
    @Transactional
    public ToJson<AttendLeaveParam> insertattendLeaveParam(AttendLeaveParam attendLeaveParam){
        ToJson<AttendLeaveParam> json = new ToJson<AttendLeaveParam>(1, "error");
        try{
            int count= (int) attendLeaveParamMapper.insertSelective(attendLeaveParam);
            if(count>0){
                json.setMsg("ok");
                json.setFlag(0);
            }
        }catch(Exception e){
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return  json;
    }

    /**
     * 修改年假参数
     * @param attendLeaveParam
     * @return
     */
    @Transactional
    public Boolean updateattendLeaveParam(AttendLeaveParam attendLeaveParam){

        int count;
        if(attendLeaveParam!=null) {
                 count = (int) attendLeaveParamMapper.insertSelective(attendLeaveParam);
            if (count > 0) {
                return true;
            }
        }
        return  false;
    }

    /**
     * 删除年假规则
     * @param attendLeaveId
     * @return
     */
    public ToJson<AttendLeaveParam> deleteattendLeaveParam(int attendLeaveId){
        ToJson<AttendLeaveParam> json = new ToJson<AttendLeaveParam>(1, "error");
        try{
            int count=attendLeaveParamMapper.deleteByPrimaryKey(attendLeaveId);
            if(count>0){
                json.setMsg("ok");
                json.setFlag(0);
            }
        }catch(Exception e){
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return  json;
    }

    /**
     * 根据ID 查询年假参数详情
     * @param attendLeaveId
     * @return
     */
    public ToJson<AttendLeaveParam> selHolidayById(int attendLeaveId){
        ToJson<AttendLeaveParam> json = new ToJson<AttendLeaveParam>(1, "error");
        try{
            AttendLeaveParam attendLeaveParam=attendLeaveParamMapper.selectByPrimaryKey(attendLeaveId);
            json.setObject(attendLeaveParam);
            json.setMsg("ok");
            json.setFlag(0);
        }catch(Exception e){
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return  json;
    }

    /**
     * 根据条件查询年假参数
     * @param attendLeaveParam
     * @return
     */
    public ToJson<AttendLeaveParam> selHoliday(AttendLeaveParam attendLeaveParam){
        ToJson<AttendLeaveParam> json = new ToJson<AttendLeaveParam>(1, "error");
        try{
            List<AttendLeaveParam> list=attendLeaveParamMapper.selectAttendLeaveParam(attendLeaveParam);
            json.setObj(list);
            json.setMsg("ok");
            json.setFlag(0);
        }catch(Exception e){
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return  json;
    }

}
